#include "menu.h"

//1、添加联系人信息
void addPerson(Addressbooks *abs){
	//判断电话本是否满了
	if (abs->m_Size == MAX){
		cout << "通讯录已满，无法添加" << endl;
		return;
	}else{
		//姓名
		string name;
		cout << "请输入姓名：" << endl;
		cin >> name;
		abs->personArray[abs->m_Size].m_Name = name;

		//性别
		cout << "请输入性别：" << endl;
		cout << "1 -- 男" << endl;
		cout << "2 -- 女" << endl;

		int sex = 0;
		while (true){
			cin >> sex;
			if (sex == 1 || sex == 2){
				abs->personArray[abs->m_Size].m_Sex = sex;
				break;
			}
			cout << "输入有误，请重新输入：";
		}

		//年龄
		cout << "请输入年龄：" << endl;
		int age = 0;
		cin >> age;
		abs->personArray[abs->m_Size].m_Age = age;

		//联系电话
		cout << "请输入联系电话：" << endl;
		string phone = "";
		cin >> phone;
		abs->personArray[abs->m_Size].m_Phone = phone;

		//家庭住址
		cout << "请输入家庭住址：" << endl;
		string address;
		cin >> address;
		abs->personArray[abs->m_Size].m_Addr = address;

		//更新通讯录人数
		abs->m_Size++;

		cout << "添加成功。" << endl;
	}

	cout << "是否继续添加(y/n):" << endl;
	string readd;
	cin >> readd;
	if(readd == "y"){
		addPerson(abs);
	}
	system("cls"); // 清除屏幕窗口
}